package com.szrt.oa.student.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.szrt.oa.student.dao.StudentDao;
import com.szrt.oa.student.entity.StudentEntity;

@Service
public class StudentServiceImpl implements StudentService{
	
	@Autowired
	private StudentDao dao;
	
	Map<String, Object> map=new HashMap<String, Object>();

	@Transactional(readOnly=false)
	@Override
	public Map<String, Object> deleteById(StudentEntity entity) {
		
		
		try {
			int result = dao.deleteById(entity);
			map.put("result", result);
			map.put("code", "200");
		} catch (Exception e) {
			map.put("code", "500");
			e.printStackTrace();
		}
		return map;
	}
	
	@Transactional(readOnly=false)
	@Override
	public Map<String, Object> update(StudentEntity entity) {
		
		try {
			int result = dao.update(entity);
			map.put("result", result);
			map.put("code", "200");
		} catch (Exception e) {
			map.put("code", "500");
			e.printStackTrace();
		}
		return map;
		
	}
	@Transactional(readOnly=false)
	@Override
	public Map<String, Object> add(StudentEntity entity) {
		
		try {
			int result = dao.add(entity);
			map.put("result", result);
			map.put("code", "200");
		} catch (Exception e) {
			map.put("code", "500");
			e.printStackTrace();
		}
		return map;
		
	}
	@Transactional(readOnly=true)
	@Override
	public Map<String, Object> findById(StudentEntity entity) {
		
		try {
			StudentEntity result = dao.findById(entity);
			map.put("result", result);
			map.put("code", "200");
		} catch (Exception e) {
			map.put("code", "500");
			e.printStackTrace();
		}
		return map;
	}

}
